package sy.util;

import sy.pageModel.Json;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class StringUtil {
    public static boolean isNullOrEmpty(String s) {
    	return s == null || "".equals(s.trim());
    }
    
    public static String nullToEmpty(String s) {
    	if(isNullOrEmpty(s) || "null".equalsIgnoreCase(s.trim())) {
    		return "";
    	}
    	return s;
    }

	public static String getId() {
		return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	}

	public static void setId(String id) {
		id = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	}
	
	public static String getDate() {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
	}

	//public static String id=new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
	//public static String date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

	public static Json findJson(int rows, String val){
		Json js=new Json();
		if (rows>0) {
			js.setSuccess(true);
			js.setMsg(val+"成功");
		}else{
			js.setMsg(val+"失败");
			js.setSuccess(false);
		}
	return js;
	}

	public static Map<String,String> findMap(String pic){
		Map map=new HashMap();
		if (pic!=null && !"".equals(pic)) {
			String str = pic.replace("\"", "");
			map.put("pic","uploadfiles/" + str);
			map.put("id",str.split("\\.")[0]);
		}else {
			map.put("id",getId());
			map.put("pic","");
		}
		return map;
	}

	public static String findStr(String pic){
		if (pic!=null && !"".equals(pic)) {
			String str = pic.replace("\"", "");
			String str1[]=str.split("/");
			if (str1.length==1)pic="uploadfiles/" + str;
		}else pic="";
		return pic;
	}
}
